<?php
$page_title = "Sondaj - Fifaonline.ro | Campionate fifa virtuale | Stiri sportive";
include_once("top.php");
if (!isset($_SESSION['identitate']))
{
	header("Location: http://localhost");
	exit();
}
if(isset($_POST["submitted"])){
	require_once("/includes/mysql_connect.php");
	$pollname = $_POST["pollname"];
	$target_path = "uploads/";
		$target_path = $target_path . $pollname. "poll.jpg";
	if(isset($_POST["question"])) {
		$question = escape_data($_POST["question"]);
	}
	else {
		$question = FALSE;
	}
	if(isset($_POST["answer1"])){
	$answer1 = escape_data($_POST["answer1"]);
	}
	else {
		$answer1 = FALSE;
	}
	if(isset($_POST["answer2"])){
		$answer2 = escape_data($_POST["answer2"]);
	}
	else {
		$answer2 = FALSE;
	}
	if(isset($_POST["answer3"])) {
		$answer3 = escape_data($_POST["answer3"]);
	}
	else {
		$answer3 = FALSE;
	}
	if(isset($_POST["answer4"])){
		$answer4 = escape_data($_POST["answer4"]);
	}
	else {
		$answer4 = FALSE;
	}
	if(isset($_POST["answer5"])){
		$answer5 = escape_data($_POST["answer5"]);
	}
	else {
		$answer5 = FALSE;
	}
	if(isset($_POST["answer6"])){
		$answer6 = escape_data($_POST["answer6"]);
	}
	else {
		$answer6 = FALSE;
	}
	//Verifica poza
		if(move_uploaded_file($_FILES['upload']['tmp_name'], $target_path)) 
		{
   			echo "The file ".  basename( $_FILES['upload']['name']).  " has been uploaded";
		} 
		else
		{
    		echo "There was an error uploading the file, please try again!";
		}
	
	if($question && $answer1 && $answer2 && $answer3 && $answer4 && $answer5 && $answer6){
		$table_query = "CREATE TABLE poll_".$pollname."(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, type INT(1) NOT NULL, data VARCHAR(100) NOT NULL, votes INT DEFAULT '0', percent INT(3) DEFAULT '0')";
		$result = mysql_query($table_query) or trigger_error("Query: $table_query\n<br>MySQL Error:" .mysql_error());
		$q_query = "INSERT INTO poll_".$pollname." (type, data) VALUES (0, '$question')";
		$result = mysql_query($q_query) or trigger_error("Query: $q_query\n<br>MySQL Error:" .mysql_error());
		$a1_query = "INSERT INTO poll_".$pollname." (type, data) VALUES (1, '$answer1')";
		$result = mysql_query($a1_query) or trigger_error("Query: $a1_query\n<br>MySQL Error:" .mysql_error());
		$a2_query = "INSERT INTO poll_".$pollname." (type, data) VALUES (1, '$answer2')";
		$result = mysql_query($a2_query) or trigger_error("Query: $a2_query\n<br>MySQL Error:" .mysql_error());
		$a3_query = "INSERT INTO poll_".$pollname." (type, data) VALUES (1, '$answer3')";
		$result= mysql_query($a3_query) or trigger_error("Query: $a3_query\n<br>MySQL Error:" .mysql_error());
		$a4_query = "INSERT INTO poll_".$pollname." (type, data) VALUES (1, '$answer4')";
		$result = mysql_query($a4_query) or trigger_error("Query: $a4_query\n<br>MySQL Error:" .mysql_error());
		$a5_query = "INSERT INTO poll_".$pollname." (type, data) VALUES (1, '$answer5')";
		$result = mysql_query($a5_query) or trigger_error("Query: $a5_query\n<br>MySQL Error:" .mysql_error());
		$a6_query = "INSERT INTO poll_".$pollname." (type, data) VALUES (1, '$answer6')";
		$result = mysql_query($a6_query) or trigger_error("Query: $a6_query\n<br>MySQL Error:" .mysql_error());
	}
	elseif($question && $answer1 && $answer2 && $answer3 && $answer4 && $answer5){
		$table_query = "CREATE TABLE poll_".$pollname."(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, type INT(1) NOT NULL, data VARCHAR(100) NOT NULL, votes INT DEFAULT '0', percent INT(3) DEFAULT '0')";
		$result = mysql_query($table_query) or trigger_error("Query: $table_query\n<br>MySQL Error:" .mysql_error());
		$q_query = "INSERT INTO poll_".$pollname." (type, data) VALUES (0, '$question')";
		$result = mysql_query($q_query) or trigger_error("Query: $q_query\n<br>MySQL Error:" .mysql_error());
		$a1_query = "INSERT INTO poll_".$pollname." (type, data) VALUES (1, '$answer1')";
		$result = mysql_query($a1_query) or trigger_error("Query: $a1_query\n<br>MySQL Error:" .mysql_error());
		$a2_query = "INSERT INTO poll_".$pollname." (type, data) VALUES (1, '$answer2')";
		$result = mysql_query($a2_query) or trigger_error("Query: $a2_query\n<br>MySQL Error:" .mysql_error());
		$a3_query = "INSERT INTO poll_".$pollname." (type, data) VALUES (1, '$answer3')";
		$result= mysql_query($a3_query) or trigger_error("Query: $a3_query\n<br>MySQL Error:" .mysql_error());
		$a4_query = "INSERT INTO poll_".$pollname." (type, data) VALUES (1, '$answer4')";
		$result = mysql_query($a4_query) or trigger_error("Query: $a4_query\n<br>MySQL Error:" .mysql_error());
		$a5_query = "INSERT INTO poll_".$pollname." (type, data) VALUES (1, '$answer5')";
		$result = mysql_query($a5_query) or trigger_error("Query: $a5_query\n<br>MySQL Error:" .mysql_error());
	}
	elseif($question && $answer1 && $answer2 && $answer3 && $answer4) {
		$table_query = "CREATE TABLE poll_".$pollname."(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, type INT(1) NOT NULL, data VARCHAR(100) NOT NULL, votes INT DEFAULT '0', percent INT(3) DEFAULT '0')";
		$result = mysql_query($table_query) or trigger_error("Query: $table_query\n<br>MySQL Error:" .mysql_error());
		$q_query = "INSERT INTO poll_".$pollname." (type, data) VALUES (0, '$question')";
		$result = mysql_query($q_query) or trigger_error("Query: $q_query\n<br>MySQL Error:" .mysql_error());
		$a1_query = "INSERT INTO poll_".$pollname." (type, data) VALUES (1, '$answer1')";
		$result = mysql_query($a1_query) or trigger_error("Query: $a1_query\n<br>MySQL Error:" .mysql_error());
		$a2_query = "INSERT INTO poll_".$pollname." (type, data) VALUES (1, '$answer2')";
		$result = mysql_query($a2_query) or trigger_error("Query: $a2_query\n<br>MySQL Error:" .mysql_error());
		$a3_query = "INSERT INTO poll_".$pollname." (type, data) VALUES (1, '$answer3')";
		$result= mysql_query($a3_query) or trigger_error("Query: $a3_query\n<br>MySQL Error:" .mysql_error());
		$a4_query = "INSERT INTO poll_".$pollname." (type, data) VALUES (1, '$answer4')";
		$result = mysql_query($a4_query) or trigger_error("Query: $a4_query\n<br>MySQL Error:" .mysql_error());
	}
	elseif($question && $answer1 && $answer2 && $answer3) {
		$table_query = "CREATE TABLE poll_".$pollname."(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, type INT(1) NOT NULL, data VARCHAR(100) NOT NULL, votes INT DEFAULT '0', percent INT(3) DEFAULT '0')";
		$result = mysql_query($table_query) or trigger_error("Query: $table_query\n<br>MySQL Error:" .mysql_error());
		$q_query = "INSERT INTO poll_".$pollname." (type, data) VALUES (0, '$question')";
		$result = mysql_query($q_query) or trigger_error("Query: $q_query\n<br>MySQL Error:" .mysql_error());
		$a1_query = "INSERT INTO poll_".$pollname." (type, data) VALUES (1, '$answer1')";
		$result = mysql_query($a1_query) or trigger_error("Query: $a1_query\n<br>MySQL Error:" .mysql_error());
		$a2_query = "INSERT INTO poll_".$pollname." (type, data) VALUES (1, '$answer2')";
		$result = mysql_query($a2_query) or trigger_error("Query: $a2_query\n<br>MySQL Error:" .mysql_error());
		$a3_query = "INSERT INTO poll_".$pollname." (type, data) VALUES (1, '$answer3')";
		$result= mysql_query($a3_query) or trigger_error("Query: $a3_query\n<br>MySQL Error:" .mysql_error());
	}
	elseif($question && $answer1 && $answer2) {
		$table_query = "CREATE TABLE poll_".$pollname."(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, type INT(1) NOT NULL, data VARCHAR(100) NOT NULL, votes INT DEFAULT '0', percent INT(3) DEFAULT '0')";
		$result = mysql_query($table_query) or trigger_error("Query: $table_query\n<br>MySQL Error:" .mysql_error());
		$q_query = "INSERT INTO poll_".$pollname." (type, data) VALUES (0, '$question')";
		$result = mysql_query($q_query) or trigger_error("Query: $q_query\n<br>MySQL Error:" .mysql_error());
		$a1_query = "INSERT INTO poll_".$pollname." (type, data) VALUES (1, '$answer1')";
		$result = mysql_query($a1_query) or trigger_error("Query: $a1_query\n<br>MySQL Error:" .mysql_error());
		$a2_query = "INSERT INTO poll_".$pollname." (type, data) VALUES (1, '$answer2')";
		$result = mysql_query($a2_query) or trigger_error("Query: $a2_query\n<br>MySQL Error:" .mysql_error());
	}
	else {
		echo "A aparut o eroare";
	}
	mysql_close();
}
?>
<form action="poll_create.php" method="post" enctype="multipart/form-data">
<fieldset>
<table>
<tr><td><p class="text2">Poll Name: </p></td><td><input type="text" name="pollname" /></td></tr>
<tr><td><p class="text2">Question: </p></td><td><input type="text" name="question" size="50"/></td></tr>
<tr><td><p class="text2">Answer1: </p></td><td><input type="text" name="answer1" /></td></tr>
<tr><td><p class="text2">Answer2: </p></td><td><input type="text" name="answer2" /></td></tr>
<tr><td><p class="text2">Answer3: </p></td><td><input type="text" name="answer3" /></td></tr>
<tr><td><p class="text2">Answer4: </p></td><td><input type="text" name="answer4" /></td></tr>
<tr><td><p class="text2">Answer5: </p></td><td><input type="text" name="answer5" /></td></tr>
<tr><td><p class="text2">Answer6: </p></td><td><input type="text" name="answer6" /></td></tr>
<input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
<tr>
<td><br /><p class="text2">Imagine: </p></td>
<td><input type="file" name="upload" /></td>
</tr>
</table>
<input type="submit" value="Create" name="submit" />
<input type="hidden" value="TRUE" name="submitted" />
</form>
</fieldset>
<a href="logout.php">Logout</a><br>
<a href="manage.php">Manage</a><br>
<a href="quotes.php">Quotes</a><br />
<?php
include_once("end.php");
?>